<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: product_tell_a_friend.php 135 2013-09-22 07:30:55Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 135 $
* 	zuletzt geaendert von:	$Author$
* 	Datum:					$Date: 2013-09-22 07:30:55 +0000 (Sun, 22 Sep 2013) $
*
* 	SEO:mercari by Siekiera Media
* 	http://www.seo-mercari.de
*
* 	Copyright (c) since 2011 SEO:mercari
* --------------------------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */

$module_smarty = new Smarty();

if(isset($_POST['action']) && $_POST['action'] == 'tell_a_friend') {
	if(!empty($_POST['email_sender']) && !empty($_POST['email_recipient']) && !empty($_POST['name_sender']) && !empty($_POST['name_recipent'])) {
		
		$smarty = new Smarty;
		
		$smarty->assign('NAME', $_POST['name_recipent']);
		$smarty->assign('MESSAGE', sprintf(TELL_A_FRIEND_MESSAGE, '<a href="'.HTTP_SERVER.DIR_WS_CATALOG.'">'.STORE_NAME.'</a>'));
		if(!empty($product->data['products_image']))
			$smarty->assign('P_IMAGE', '<img style="float:left; margin: 0 10px 10px 0" src="'.HTTP_SERVER.DIR_WS_CATALOG.DIR_WS_THUMBNAIL_IMAGES.$product->data['products_image'].'" alt="'.$product->data['products_name'].'" />');
		
		$smarty->assign('P_NAME', '<a href="'.href_link(FILENAME_PRODUCT_INFO, 'products_id='.$_POST['products_id']).'">'.$product->data['products_name'].'</a>');
		$smarty->assign('P_DESC', $product->data['products_short_description']);
		$smarty->assign('SEND_NAME', $_POST['name_sender']);
		
		$smarty->caching = false;
		require_once(DIR_FS_INC.'inc.get_mail_body.php');
		$html_mail  = $smarty->fetch('html:tell_friend');
		$html_mail .= $signatur_html;
		$txt_mail  = $smarty->fetch('txt:tell_friend');
		$txt_mail .= $signatur_text;
		require_once(DIR_FS_INC.'inc.get_mail_data.php');
		$mail_data = get_mail_data('tell_friend');
				
		php_mail($_POST['email_sender'],
				$_POST['name_sender'],
				$_POST['email_recipient'],
				$_POST['name_recipent'],
				'',
				$_POST['email_sender'],
				$_POST['name_sender'],
				'',
				'',
				$mail_data['EMAIL_SUBJECT'],
				$html_mail,
				$txt_mail);
		
		$_SESSION['info_message'] = urlencode(sprintf(TELL_A_FRIEND_SUCCESS, $_POST['name_recipent']));
		
	} else
		$_SESSION['info_message'] = urlencode(TELL_A_FRIEND_ERROR);

	redirect(href_link(FILENAME_PRODUCT_INFO, 'products_id='.$_POST['products_id']).'#tell_a_friend');
}

$module_smarty->assign('TELL_FORM', draw_form('product_tell_a_friend', href_link(FILENAME_PRODUCT_INFO, 'products_id='.$product->data['products_id'])).draw_hidden_field('action', 'tell_a_friend').draw_hidden_field('products_id', $product->data['products_id']));
if(isset($_SESSION['customer_id'])) {
	$get_data = $db->db_query("SELECT customers_email_address FROM ".TABLE_CUSTOMERS." WHERE customers_id = '".$_SESSION['customer_id']."'");
	$module_smarty->assign('NAME_SENDER', draw_input_field('name_sender', (isset($_POST['email_sender']) ? $_POST['email_sender'] : $_SESSION['customer_first_name'].' '.$_SESSION['customer_last_name'])));
	$module_smarty->assign('EMAIL_SENDER', draw_input_field('email_sender', (isset($_POST['name_sender']) ? $_POST['name_sender'] : $get_data->fields['customers_email_address'])));
} else {
	$module_smarty->assign('NAME_SENDER', draw_input_field('name_sender', $_POST['name_sender']));
	$module_smarty->assign('EMAIL_SENDER', draw_input_field('email_sender', $_POST['email_sender']));
}
	
$module_smarty->assign('EMAIL_RECIPIENT', draw_input_field('email_recipient', $_POST['name_recipent']));
$module_smarty->assign('NAME_RECIPENT', draw_input_field('name_recipent', $_POST['name_recipent']));

$module_smarty->assign('BUTTON_SEND', image_submit('', IMAGE_BUTTON_SEND));
$module_smarty->assign('language', $_SESSION['language']);

if(isset($_SESSION['info_message']))
	$module_smarty->assign('info', urldecode($_SESSION['info_message']));
unset($_SESSION['info_message']);

$module_smarty->caching = false;
$product_tell_a_friend = $module_smarty->fetch(CURRENT_TEMPLATE.'/module/products_tell_a_friend.html');

$info_smarty->assign('MODUL_TELL_A_FRIEND', $product_tell_a_friend);